<template>
	<view class="configuration">
		<view class="top-box">
			<el-breadcrumb separator="/">
				<el-breadcrumb-item>数据统计</el-breadcrumb-item>
				<el-breadcrumb-item>{{ getBreadcrumb }}</el-breadcrumb-item>
			</el-breadcrumb>
			
			<view class="header-serch flex ac jcsb">
				<view class="search-box flex ac">
					<view class="search flex ac">
						<view class="search-title" v-if="!second">链接ID：</view>
						<!-- <view class="search-title" v-else>渠道：</view> -->
						<el-input v-model="name" placeholder="请输入链接ID"></el-input>
					</view>
					<view class="search-btn">
						<el-button type="primary" class="search-button" @click='search'>查询</el-button>
					</view>
				</view>
				<!-- <el-button class="add-user" type="primary" @click='openDelog(0)'>+ 新增二维码</el-button> -->
			</view>
			
			<el-table 
				:data="Table.TableDataList" 
				style="width: 100%;" 
				height="calc(100vh - 298px)"
				stripe
				:header-cell-style="{background:'#E9ECEE',color:'#16171F'}">
				<el-table-column 
					show-overflow-tooltip 
					:prop="item.prop" 
					:label="item.label" 
					v-for="(item,index) in newTitleList"
					:key="index"
					:min-width="item.width">
					<template slot-scope="scope">
						<!-- 每一项的值 -->
						<span v-if="item.prop && item.prop != 'linkUrl'">{{ (item.prop == 'createTime' || item.prop == 'updateTime')? new Date(scope.row[item.prop]).format():scope.row[item.prop] }}</span>
						
						<span v-if="item.prop && item.prop == 'linkUrl'" @click="copyClick(scope.row)">{{ scope.row[item.prop] }}</span>
					</template>
				</el-table-column>
			</el-table>
		</view>
		<view class="footer">
			<el-pagination  
				@size-change="handleSizeChange" 
				@current-change="handleCurrentChange"
				:current-page="Table.page"  
				layout="total, prev, pager, next, jumper, sizes" 
				background 
				:total="Table.count"
				:page-sizes="[10, 12]" 
				:page-size.sync="Table.limit">
			</el-pagination>
			<view class="pageLimit">当前显示{{Table.limit}}条/页</view>
		</view>
		
		<!-- <confirm @confirmFlagClick="confirmFlagClick" :confirmFlag="confirmFlag" :title="confirmTitle"></confirm> -->
		<!-- <labelDialog :dialogVisible="addUserDialogFlag" @closeDialog="closeDialog" :title="addDialogTitle" :code="currentCode"></labelDialog> -->
	</view>
</template>

<script>
	import { Request } from '../model/request.js'
	import { Util } from '../utils/util.js'
	
	export default {
		props: {
			second: {
				type: [String, Number],
				default: 0
			}
		},
		
		computed: {
			getBreadcrumb() {
				let c = 'uv-pv统计'
				return c
			},
			
			newTitleList() {
				// if (this.second == 1) {
				// 	return this.Table.titleList1
				// } else if (this.second == 2) {
				// 	return this.Table.titleList2
				// } else {
				// 	return this.Table.titleList
				// }
				return this.Table.titleList
			}
		},
		
		data() {
			return {
				phone: '',
				name: '',
				Table: {
					titleList: [
						{
							prop: "linkId",
							label: "链接ID",
							width: '10%'
						},{
							prop: "uvNumber",
							label: "uv总量",
							width: '10%'
						},
						{
							prop: "pvNumber",
							label: "pv总量",
							width: '10%'
						},
						{
							prop: "linkUrl",
							label: "广告链接",
							width: '30%'
						},
						// {
						// 	prop: "createTime",
						// 	label: "创建时间",
						// 	width: '15%'
						// },
						{
							prop: "updateTime",
							label: "更新时间",
							width: '15%'
						}
					], 
					TableDataList: [],
					page: 1,
					limit: 10,
					count: 0
				},
				
				addUserDialogFlag: false,
				addDialogTitle: '',
				currentCode: ''
			}
		},
		
		mounted() {
			this.initTable()
		},
		
		watch: {
			second(newVal, oldVal) {
				this.phone = ''
				this.name = ''
				this.Table.page = 1
				this.Table.limit = 10
				this.Table.count = 0
				this.initTable()
			}
		},
		
		methods: {
			search() {
				this.initTable()
			},
			
			async initTable(page) {
				this.Table.TableDataList = []
				if (!Util.isNull(page)) {
					this.Table.page = page
				} else {
					this.Table.page = 1
				}
				let res = await Request.COUNTFINDALL(this.Table.page, this.Table.limit, this.name)
				if (!Util.isNull(res)) {
					this.Table.TableDataList = res.data.records
					this.Table.count = res.data.total
				} else {
					this.Table.TableDataList = null
				}
			},
			
			// 用户，活动，广告 【创建用户，新增链接】
			// openDelog(i, item=null) {
			// 	if (i) {
			// 		this.addDialogTitle = '下载预览二维码'
			// 		this.currentCode = item.QRcode
			// 	} else {
			// 		this.addDialogTitle = '新增二维码'
			// 	}
			// 	this.addUserDialogFlag = true
			// },
			
			// closeDialog() {
			// 	this.addUserDialogFlag = false
			// },
			
			handleSizeChange(val) {
				console.log(`每页 ${val} 条`);
				this.initTable()
			},
			
			handleCurrentChange(val) {
				console.log(`当前页: ${val}`, this.Table.page);
				this.initTable(val)
			},
			
			copyClick(item) { // 复制活动链接
				Util.copy(item.linkUrl)
			}
		}
	}
</script>

<style scoped>
	.configuration {
		/* padding: 20px 40px 50px; */
		position: relative;
	}
	
	.top-box {
		padding: 20px 40px 0;
	}
	
	.header-serch {
		margin: 30px 0;
	}
	
	.search-title {
		min-width: 64px;
		font-size: 14px;
		font-weight: 500;
		color: #16171F;
		/* text-align: right; */
	}
	
	.search-btn {
		margin-left: 30px;
	}
	
	.footer {
		width: 100%;
		height: 40px;
		display: flex;
		align-items: center;
		/* position: absolute; */
		/* left: 0; */
		/* bottom: 0px; */
		justify-content: center;
		height: 130px;
		background: #FFFFFF;
		box-shadow: 0px -7px 9px 0px rgba(0, 0, 0, 0.02);
	}
	
	.del-color {
		color: #D1141F;
	}
	
	.start-color {
		color: #4A92FD;
	}
	
	>>> .el-input__inner{
		height: 32px;
	}
	
	.search-button, .add-user {
		font-size: 14px;
		height: 32px;
		line-height: 32px;
		padding-top: 0;
		padding-bottom: 0;
	}
	
	.qr-code-box {
		height: 50px;
	}
	
	.tki-qrcode {
		height: 100%;
	}
</style>
